package com.oauth.components.client.ui.gadgets;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.HasValueChangeHandlers;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ProfileInfoPanel extends Composite implements HasValueChangeHandlers<String> {

	private static ConnectionPanelUiBinder uiBinder = GWT.create(ConnectionPanelUiBinder.class);

	interface ConnectionPanelUiBinder extends UiBinder<HorizontalPanel, ProfileInfoPanel> {
	}

	@UiField
	HorizontalPanel hPanel1;

	@UiField
	HTMLPanel hPanel2AlignLeft;

	@UiField
	Image profileImage;

	@UiField
	Label name;

	@UiField
	Label headLine;

	@UiField
	EditableLabel status;

	public ProfileInfoPanel() {
		initWidget(uiBinder.createAndBindUi(this));
		hPanel1.setCellHorizontalAlignment(hPanel2AlignLeft, VerticalPanel.ALIGN_LEFT);
	}

	public void setData(String pProfileImageUrl, String pName, String pStatus) {
		setProfileImageUrl(pProfileImageUrl);
		setStatus(pStatus);
		setName(pName);
	}

	public void setData(String pProfileImageUrl, String pName, String pStatus, String pHeadLine) {
		setData(pProfileImageUrl, pName, pStatus);
		setHeadLine(pHeadLine);
	}

	/**
	 * Use this method to set real orkut url.
	 * 
	 * @param pProfileImageUrl
	 */
	public void setProfileImageUrl(String pProfileImageUrl) {
		profileImage.setUrl(pProfileImageUrl);
	}

	public void setStatus(String pStatus) {
		System.out.println("Status=" + pStatus);
		status.setValue(pStatus);
	}

	public void setName(String pName) {
		name.setText(pName);
	}

	public void setHeadLine(String pHeadLine) {
		headLine.setText(pHeadLine);
	}

	public void setSpacing(int spacing) {
		hPanel1.setSpacing(spacing);
	}

	public void setHeadLineEnabled(boolean pEnabled) {
		headLine.setVisible(pEnabled);
	}

	public void setWidth(String width) {
		hPanel1.setWidth(width);
	}

	/**
	 * Use this method to set default profile image url.
	 * 
	 * @param pUrl
	 */
	public void setDefaultImageUrl(String pUrl) {
		profileImage.setUrl(pUrl);
	}

	@Override
	public HandlerRegistration addValueChangeHandler(ValueChangeHandler<String> pHandler) {
		return status.addValueChangeHandler(pHandler);
	}
}
